﻿using System;
using System.Web.UI.WebControls;
using TPG.SharePoint.Workflow;

namespace $rootnamespace$
{
    public class $safeitemname$
        : AssociationPage
    {
        protected TextBox MyAssociationField = null;
        
        protected override void OnLoad(EventArgs e)
        {
            if(IsNewAssociation == false && IsInitialLoad)
            {
                string dataString = GetAssociationData();
                AssociationData data = 
                    WorkflowDataSerializer.DeserializeFromXmlString<AssociationData>(dataString);
                MyAssociationField.Text = data.MyField;
            }
            base.OnLoad(e);
        }

        protected void OkButton_Click(object sender, EventArgs e)
        {
            /*
             * The AssociationData class is added as a sample and can
             * be customized to fit your solution. You can also replace 
             * it with your own custom data object.
             * */
            AssociationData data = new AssociationData(); 
            data.MyField = MyAssociationField.Text;
            string dataString = WorkflowDataSerializer.SerializeToXmlString<AssociationData>(data);
            CommitAssocation(dataString);
        }

        protected void CancelButton_Click(object sender, EventArgs e)
        {
            CancelAssociation();
        }
    
        public class AssociationData
        {
            public string MyField{ get; set;}
        }
    }
}
